#include "framework.h"
#include "ui_framework.h"
#include <QGraphicsDropShadowEffect>

FrameWork::FrameWork(QWidget *parent)
    : MouseEvent(parent)
    , ui(new Ui::FrameWork)
{
    ui->setupUi(this);

    m_pStatusBar = new StatusBar;
    m_pTitleBar = new TitleBar;
    m_pCenterWidget = new CenterWidget;
    m_pCenterMainWidget = new centerMainWidget;
    m_pRegisterWidget = new RegisterWidget;
    m_pForgetWidget = new ForgetPasswordWidget;

    QWidget *container = new QWidget(this);//将QStackedLayout放入Qwidget中
    m_pStackLayout = new QStackedLayout(container);
    m_pStackLayout->addWidget(m_pCenterWidget);//index = 0
    m_pStackLayout->addWidget(m_pCenterMainWidget);//index = 1
    m_pStackLayout->addWidget(m_pRegisterWidget);//index = 2
    m_pStackLayout->addWidget(m_pForgetWidget);//index = 3

    ui->centerWidgetLayout->addWidget(container);
    ui->statusLayout->addWidget(m_pStatusBar);
    ui->titleBarLayout->addWidget(m_pTitleBar);

    m_pSettingManage = new SettingManage(this);//从配置文件中读取上一次的位置和大小
    if(!m_pSettingManage->getValue("WindowPosition/MaxWidget").toBool()){
        this->setGeometry(m_pSettingManage->getValue("WindowPosition/x").toInt(),
                          m_pSettingManage->getValue("WindowPosition/y").toInt(),
                          m_pSettingManage->getValue("WindowPosition/width").toInt(),
                          m_pSettingManage->getValue("WindowPosition/height").toInt()
                          );
    }else{
        this->showMaximized();
    }

    connect(m_pCenterWidget,&CenterWidget::sendMessage,m_pStatusBar,&StatusBar::onRecvMessage);     //登录页-状态栏
    connect(m_pRegisterWidget,&RegisterWidget::sendMessage,m_pStatusBar,&StatusBar::onRecvMessage);     //注册页-状态栏
    connect(m_pForgetWidget,&ForgetPasswordWidget::sendMessage,m_pStatusBar,&StatusBar::onRecvMessage);     //忘记密码页-状态栏

    connect(m_pCenterWidget,&CenterWidget::selectStackWidget,m_pStackLayout,[=](int mainWidget,QString username){
        m_pStackLayout->setCurrentIndex(mainWidget);
        m_pCenterMainWidget->setUserInfo(username);
    });      //传递登录角色用户名
    connect(m_pRegisterWidget,&RegisterWidget::selectStackWidget,m_pStackLayout,&QStackedLayout::setCurrentIndex);      //
    connect(m_pForgetWidget,&ForgetPasswordWidget::selectStackWidget,m_pStackLayout,&QStackedLayout::setCurrentIndex);      //
}

FrameWork::~FrameWork()
{
    delete ui;
}




